function [avgs tonsostuff] = popstats_within_doughnut(data,censusdata,target_lat,target_long,radius_out,radius_in)
% Let's find it for a radius now

%credit file geocodes from credit bureau
%census geocodes from census

% number of points within radius of miles
r = sqrt((69*(data(:,1)-target_lat)).^2 + ((69*cos(pi*target_lat/180))*(data(:,2)-target_long)).^2);
r2 = sqrt((69*(censusdata(:,2)-target_lat)).^2 + ((69*cos(pi*target_lat/180))*(censusdata(:,3)-target_long)).^2);
area_points = data(r <= radius_out & r >= radius_in,:);
census_area_points = censusdata(r2 <= radius_out & r2 >= radius_in,:);

r = r(r <= radius_out & r >= radius_in);
r2 = r2(r2 <= radius_out & r2 >= radius_in);


avg_area_points = sum(area_points, 1)./length(r);
avgs = [avg_area_points length(r)];

totalpop = sum(census_area_points(:,4));
perc_nonwhite = 1 - sum(census_area_points(:,5))/totalpop;
perc_black = sum(census_area_points(:,6))/totalpop;
perc_hispanic = (sum(census_area_points(:,137)))/(sum(census_area_points(:,12)));


ltHS_M = sum(sum(census_area_points(:,22:29)))/sum(census_area_points(:,21));
gtHS_M = sum(sum(census_area_points(:,31:37)))/sum(census_area_points(:,21));
eqHS_M = sum(sum(census_area_points(:,30)))/sum(census_area_points(:,21));

ltHS_F = sum(sum(census_area_points(:,39:46)))/sum(census_area_points(:,38));
gtHS_F = sum(sum(census_area_points(:,48:54)))/sum(census_area_points(:,38));
eqHS_F = sum(sum(census_area_points(:,47)))/sum(census_area_points(:,38));

inc_lt10k    = (sum(census_area_points(:,56)))/(sum(census_area_points(:,55)));
inc_10k15k   = (sum(census_area_points(:,57)))/(sum(census_area_points(:,55)));
inc_15k20k   = (sum(census_area_points(:,58)))/(sum(census_area_points(:,55)));
inc_20k15k   = (sum(census_area_points(:,59)))/(sum(census_area_points(:,55)));
inc_25k30k   = (sum(census_area_points(:,60)))/(sum(census_area_points(:,55)));
inc_30k35k   = (sum(census_area_points(:,61)))/(sum(census_area_points(:,55)));
inc_35k40k   = (sum(census_area_points(:,62)))/(sum(census_area_points(:,55)));
inc_40k45k   = (sum(census_area_points(:,63)))/(sum(census_area_points(:,55)));
inc_45k50k   = (sum(census_area_points(:,64)))/(sum(census_area_points(:,55)));
inc_50k60k   = (sum(census_area_points(:,65)))/(sum(census_area_points(:,55)));
inc_60k75k   = (sum(census_area_points(:,66)))/(sum(census_area_points(:,55)));
inc_75k100k  = (sum(census_area_points(:,67)))/(sum(census_area_points(:,55)));
inc_100k125k = (sum(census_area_points(:,68)))/(sum(census_area_points(:,55)));
inc_125k150k = (sum(census_area_points(:,69)))/(sum(census_area_points(:,55)));
inc_150k200k = (sum(census_area_points(:,70)))/(sum(census_area_points(:,55)));
inc_200kplus = (sum(census_area_points(:,71)))/(sum(census_area_points(:,55)));


married_M = (sum(census_area_points(:,75)))/(sum(census_area_points(:,73)));
nonmarried_M = (sum(census_area_points(:,74)))/(sum(census_area_points(:,73)));
widowed_M = (sum(census_area_points(:,80)))/(sum(census_area_points(:,73)));
divorced_M = (sum(census_area_points(:,81)))/(sum(census_area_points(:,73)));

married_F = (sum(census_area_points(:,84)))/(sum(census_area_points(:,82)));
nonmarried_F = (sum(census_area_points(:,83)))/(sum(census_area_points(:,82)));
widowed_F = (sum(census_area_points(:,89)))/(sum(census_area_points(:,82)));
divorced_F = (sum(census_area_points(:,90)))/(sum(census_area_points(:,82)));

fam2pers_household = (sum(census_area_points(:,93)))/(sum(census_area_points(:,92)));
fam3pers_household = (sum(census_area_points(:,94)))/(sum(census_area_points(:,92)));
fam4pers_household = (sum(census_area_points(:,95)))/(sum(census_area_points(:,92)));
fam5pers_household = (sum(census_area_points(:,96)))/(sum(census_area_points(:,92)));
fam6pers_household = (sum(census_area_points(:,97)))/(sum(census_area_points(:,92)));
fam7pers_household = (sum(census_area_points(:,98)))/(sum(census_area_points(:,92)));
nonfam1pers_household = (sum(census_area_points(:,100)))/(sum(census_area_points(:,99)));
nonfam2pers_household = (sum(census_area_points(:,101)))/(sum(census_area_points(:,99)));
nonfam3pers_household = (sum(census_area_points(:,102)))/(sum(census_area_points(:,99)));
nonfam4pers_household = (sum(census_area_points(:,103)))/(sum(census_area_points(:,99)));
nonfam5pers_household = (sum(census_area_points(:,104)))/(sum(census_area_points(:,99)));
nonfam6pers_household = (sum(census_area_points(:,105)))/(sum(census_area_points(:,99)));
nonfam7pers_household = (sum(census_area_points(:,106)))/(sum(census_area_points(:,99)));

lang_eng = (sum(census_area_points(:,108)))/(sum(census_area_points(:,107)));
lang_span = (sum(census_area_points(:,109)))/(sum(census_area_points(:,107)));
lang_euro = (sum(census_area_points(:,112)))/(sum(census_area_points(:,107)));
lang_asian = (sum(census_area_points(:,115)))/(sum(census_area_points(:,107)));
lang_other = (sum(census_area_points(:,118)))/(sum(census_area_points(:,107)));


nativeborn = (sum(census_area_points(:,122)))/(sum(census_area_points(:,121)));
foreignborn = (sum(census_area_points(:,133)))/(sum(census_area_points(:,121)));


agg_househld_income = sum(census_area_points(:,13))/totalpop;
earnings = (sum(census_area_points(:,15)))/(sum(census_area_points(:,14)));
noearnings = (sum(census_area_points(:,16)))/(sum(census_area_points(:,14)));
public_assistance = (sum(census_area_points(:,18)))/(sum(census_area_points(:,17)));
nopublic_assistance = (sum(census_area_points(:,19)))/(sum(census_area_points(:,17)));
% 
% 
% males_publicHS = (sum(census_area_points(:,54)))/(sum(census_area_points(:,49)));
% males_privateHS = (sum(census_area_points(:,55)))/(sum(census_area_points(:,49)));
% females_publicHS = (sum(census_area_points(:,62)))/(sum(census_area_points(:,57)));
% females_privateHS = (sum(census_area_points(:,63)))/(sum(census_area_points(:,49)));




tonsostuff = [totalpop perc_nonwhite perc_black perc_hispanic ...
    ltHS_M gtHS_M eqHS_M ltHS_F gtHS_F eqHS_F inc_lt10k ...
    inc_10k15k inc_15k20k inc_20k15k inc_25k30k inc_30k35k...
    inc_35k40k inc_40k45k inc_45k50k inc_50k60k inc_60k75k...
    inc_75k100k inc_100k125k inc_125k150k inc_150k200k ...
    inc_200kplus married_M nonmarried_M widowed_M ...
    divorced_M married_F nonmarried_F widowed_F ...
    divorced_F fam2pers_household fam3pers_household ...
    fam4pers_household fam5pers_household fam6pers_household ...
    fam7pers_household nonfam1pers_household nonfam2pers_household ...
    nonfam3pers_household nonfam4pers_household nonfam5pers_household ...
    nonfam6pers_household nonfam7pers_household lang_eng lang_span ...
    lang_euro lang_asian lang_other nativeborn foreignborn  ...
    agg_househld_income earnings noearnings public_assistance ...
    nopublic_assistance length(r2)];

